// 从config.js中结构出ssoBaseUrl
import config from '@/config/config.js';
import http from '@/api/http.js'

const dictRequest = {
    /**
     * 导出数据
     * @param dict
     * @param page
     * @param limit
     */
    exportDicts(dict,page=1,limit=10){
        // 拼接url
        let url = config.sysBaseUrl + "/dict/export?page=" + page + "&limit=" + limit;
        if(dict){
            if(dict.dictName)
                url += '&dictName=' + dict.dictName;
            if(dict.dictType)
                url += '&dictType=' + dict.dictType;
            if(dict.dictStatus)
                url += '&dictStatus=' + dict.dictStatus;
        }
        // 通过超链接请求即可
        location.href = url;
    },
    /**
     * 获取当前登陆用户的信息
     * @param callBack
     */
    getDictByType(dictType,callBack){
        if(dictType){
            http.get(config.sysBaseUrl + "/dict/getDict?dictType=" + dictType,callBack);
        }
    },
    /**
     * 多条件分页查询
     * @param dict
     * @param callBack
     */
    list(dict,page=1,limit=10,callBack){
        // 拼接url
        let url = config.sysBaseUrl + "/dict/list?page=" + page + "&limit=" + limit;
        if(dict){
            if(dict.dictName)
                url += '&dictName=' + dict.dictName;
            if(dict.dictType)
                url += '&dictType=' + dict.dictType;
            if(dict.dictStatus)
                url += '&dictStatus=' + dict.dictStatus;
        }
        http.get(url,callBack);
    },
    // 同步请求的方法
    async getDictByTypeAsync(dictType){
        if(dictType){
            let result = await http.getSync(config.sysBaseUrl + "/dict/getDict?dictType=" + dictType);
            console.log(result.data)
            return result.data;
        }
        return undefined;
    }
}


export default dictRequest;